define([
    'map','getolechartzqdata','pie','line','bar','timeLinestatistics'
], function(map,getzqdata,pie,line,bar,timeLinestatistics) {
    'use strict';

    let _setting = {
        isinit: false
    }

    let pie_echartLayers = {};
    let line_echartLayers = {};
    let bar_echartLayers = {};
    let timelinestatistics_echartLayers = {};

    function init() {
        if (_setting.isinit) {
            return _setting.isinit
        }
        _setting.isinit = true;
        return false;
    }

    function setmodel(type, name) {
        !name && (name = type);
        let mateData = getzqdata.getdata(type);
        switch (type) {
            case "pie":
                if (name && pie_echartLayers[name]) {
                    pie_echartLayers[name].setMateData(mateData);
                }else{
                    pie_echartLayers[name] = new pie(mateData);
                }
                pie_echartLayers[name].init();
                pie_echartLayers[name].setVisible(true);
                break;
            case "line":
                if (name && line_echartLayers[name]) {
                    line_echartLayers[name].setMateData(mateData);
                }else{
                    line_echartLayers[name] = new line(mateData);
                }
                line_echartLayers[name].init();
                line_echartLayers[name].setVisible(true);
                break;
            case "bar":
                if (name && bar_echartLayers[name]) {
                    bar_echartLayers[name].setMateData(mateData);
                }else{
                    bar_echartLayers[name] = new bar(mateData);
                }
                bar_echartLayers[name].init();
                bar_echartLayers[name].setVisible(true);
                break;
            case "timelinestatistics":
                if (name && timelinestatistics_echartLayers[name]) {
                    timelinestatistics_echartLayers[name].setMateData(mateData);
                }else{
                    timelinestatistics_echartLayers[name] = new timeLinestatistics(mateData);
                }
                timelinestatistics_echartLayers[name].init();
                timelinestatistics_echartLayers[name].setVisible(true);
                break;
        }
        if (!$("#transStyle").hasClass("dark")) {
            map.setdarktheam(document.getElementById("transStyle"));
        } 
    }

    function setVisible(type, name, bool) {
        !name && (name = type);
        // 隐藏所有模块
        if (arguments.length === 1 && typeof arguments[0] === "boolean" && !arguments[0]) {
            Object.keys(pie_echartLayers).forEach(key => {
                pie_echartLayers[key].setVisible(arguments[0]);
            })
            Object.keys(line_echartLayers).forEach(key => {
                line_echartLayers[key].setVisible(arguments[0]);
            })
            Object.keys(bar_echartLayers).forEach(key => {
                bar_echartLayers[key].setVisible(arguments[0]);
            })
            Object.keys(timelinestatistics_echartLayers).forEach(key => {
                timelinestatistics_echartLayers[key].setVisible(arguments[0]);
            })
            return;
        }
        // 除了指定模块，其他均隐藏
        if (arguments.length === 1 && typeof arguments[0] === "string") {
            arguments[0] !== "pie" && Object.keys(pie_echartLayers).forEach(key => {
                pie_echartLayers[key].setVisible(false);
            })
            arguments[0] !== "line" && Object.keys(line_echartLayers).forEach(key => {
                line_echartLayers[key].setVisible(false);
            })
            arguments[0] !== "bar" && Object.keys(bar_echartLayers).forEach(key => {
                bar_echartLayers[key].setVisible(false);
            })
            arguments[0] !== "timelinestatistics" && Object.keys(timelinestatistics_echartLayers).forEach(key => {
                timelinestatistics_echartLayers[key].setVisible(false);
            })
            return;
        }
        // 显隐指定模块的指定数据
        if (arguments.length === 3) {
            switch (type) {
                case "pie":
                    pie_echartLayers[name].setVisible(bool);
                    break;
                case "line":
                    line_echartLayers[name].setVisible(bool);
                    break;
                case "bar":
                    bar_echartLayers[name].setVisible(bool);
                    break;
                case "timelinestatistics":
                    timelinestatistics_echartLayers[type].setVisible(bool);
                    break;
            }
        }
    }

    function destory() {
        // echartslayer.remove();
        // _setting.isinit = false;
    }

    return{
        init: init,
        setmodel: setmodel,
        setVisible: setVisible,
        destory: destory
    }
});